﻿using ShareFrame.Entity.Base_Manage;
using ShareFrame.Util;
using EFCore.Sharding;
using LinqKit;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using ShareFrame.IBusiness.Base_Manage;

namespace ShareFrame.Business.Base_Manage
{
    /// <summary>
    /// 计数信息表接口实现类
    /// </summary>
    public class Base_AccessNumberBusiness : BaseBusiness<Base_AccessNumber>, IBase_AccessNumberBusiness, ITransientDependency
    {
        public Base_AccessNumberBusiness(IDbAccessor db)
            : base(db)
        {
        }

        #region 外部接口
        /// <summary>
        /// 根据条件获取分页结果集
        /// </summary>
        /// <param name="input">传入条件参数</param>
        /// <returns></returns>
        public async Task<PageResult<Base_AccessNumber>> GetDataListAsync(PageInput<ConditionDTO> input)
        {
            var q = GetIQueryable();
            var where = LinqHelper.True<Base_AccessNumber>();
            var search = input.Search;

            //筛选
            if (!search.Condition.IsNullOrEmpty() && !search.Keyword.IsNullOrEmpty())
            {
                var newWhere = DynamicExpressionParser.ParseLambda<Base_AccessNumber, bool>(
                    ParsingConfig.Default, false, $@"{search.Condition}.Contains(@0)", search.Keyword);
                where = where.And(newWhere);
            }

            return await q.Where(where).GetPageResultAsync(input);
        }

        /// <summary>
        /// 根据传入Id获取对应实体信息
        /// </summary>
        /// <param name="id">实体唯一编号</param>
        /// <returns></returns>
        public async Task<Base_AccessNumber> GetTheDataAsync(string id)
        {
            return await GetEntityAsync(id);
        }

        /// <summary>
        /// 基础添加方法
        /// </summary>
        /// <param name="data">要添加的实体信息</param>
        /// <returns></returns>
        public async Task AddDataAsync(Base_AccessNumber data)
        {
            await InsertAsync(data);
        }

        /// <summary>
        /// 基础更新方法
        /// </summary>
        /// <param name="data">要更新的实体信息</param>
        /// <returns></returns>
        public async Task UpdateDataAsync(Base_AccessNumber data)
        {
            await UpdateAsync(data);
        }

        /// <summary>
        /// 基础删除方法
        /// </summary>
        /// <param name="ids">传入条件参数</param>
        /// <returns></returns>
        public async Task DeleteDataAsync(List<string> ids)
        {
            await DeleteAsync(ids);
        }

        #endregion

        #region 私有成员

        #endregion
    }
}